package plutuscat.shishicai;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Consts;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.tomcat.util.http.fileupload.IOUtils;

/**
 *
 *@author Jack
 *2016年5月5日下午11:26:14
 */
public class Test {
	public static void main(String[] args) throws Exception {
		HttpPost httppost = new HttpPost("http://sina.aicai.com/kaijiang/open/kcResultByDate.do");

		List<NameValuePair> formparams = new ArrayList<NameValuePair>();
		formparams.add(new BasicNameValuePair("gameIndex", "301"));
		formparams.add(new BasicNameValuePair("searchDate", "2016-05-05"));
		UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
		httppost.setEntity(entity);
		httppost.addHeader("Accept", "application/json, text/javascript, */*; q=0.01");
		httppost.addHeader("Accept-Encoding", "gzip, deflate");
		httppost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
		httppost.addHeader(
				"Cookie",
				"JSESSIONID=3B660E65EEBBBE4398B2A39BDE0041A1.c73; AUM=dgxk6eUkreI0004b8UiK7423jN5nt-yqlWtWpTno5j7lw; JSESSIONID=CE754B610BD87E63FA0341C010D75DAB.c36; route=f692fe692372ddc44c563438b85f15ba; routekjgg=e79ed3f8b477b2d54438aac28584817e; VUID=294DBDA184EB428AA7C7949A6EABCE7A; CNZZDATA2028824=cnzz_eid%3D353074365-1462460179-%26ntime%3D1462460179; NAGENTID=46965");
		httppost.addHeader("Host", "sina.aicai.com");
		httppost.addHeader("Origin", "http://sina.aicai.com");
		httppost.addHeader("Referer", "http://sina.aicai.com/kaijiang/cqssc/");
		httppost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36");
		httppost.addHeader("X-Requested-With", "XMLHttpRequest");

		CloseableHttpClient httpclient = HttpClients.createDefault();
		RequestConfig requestConfig = RequestConfig.custom()
		        .setSocketTimeout(3000)
		        .setConnectTimeout(3000)
		        .build();
		httppost.setConfig(requestConfig);
		CloseableHttpResponse response =  httpclient.execute(httppost);
		InputStream in = response.getEntity().getContent();
		IOUtils.copy(in, System.out);
	}
}
